<?php

if( !defined( 'MEDIAWIKI' ) )
die(-1);

require_once('DatabaseFunctions.php');


// Set up the new special page
$dir = dirname( __FILE__ ) . '/';
$wgExtensionMessagesFiles['UserTimeline'] = $dir . 'UserTimeline.i18n.php';
$wgAutoloadClasses['UserTimeline'] = $dir . 'UserTimelineClass.php';

#install extension hook
$wgExtensionFunctions[] = "wfUserTimeline";


function wfUserTimeline(){
  global $wgRequest, $wgDBprefix, $wgOut, $wgUser, $IP, $wgUserLevels;
  $value = $wgRequest->getText( 'title' );
  $values = explode(":", $value);


  //First check if the type of content (url) is the kind to render this module (Main_Page)
  if ($values[0] == 'User') {
  
    
    
    $out .= '<div class="user_timeline">';
    $out .= '<h2>'.wfMsg( 'user_timeline' ).'</h2>';
    $out .= '<ul>';

  //////////////////////////////////////////////////////////////////

                $rel_type = $wgRequest->getVal( 'rel_type' );
		$item_type = $wgRequest->getVal( 'item_type' );

		if ( !$rel_type ) $rel_type = 1;
		if ( !$item_type ) $item_type = 'all';

		if ( $item_type == 'edits' || $item_type == 'all' ) $edits = 1;
		if ( $item_type == 'votes' || $item_type == 'all' ) $votes = 0;
		if ( $item_type == 'comments' || $item_type == 'all' ) $comments = 1;
		if ( $item_type == 'gifts' || $item_type == 'all' ) $gifts = 1;
		if ( $item_type == 'relationships' || $item_type == 'all' ) $relationships = 1;
		if ( $item_type == 'advancements' || $item_type == 'all' ) $messages = 1;
		if ( $item_type == 'awards' || $item_type == 'all' ) $system_gifts = 1;
		if ( $item_type == 'messages' || $item_type == 'all' ) $messages_sent = 1;
		if ( $item_type == 'thoughts' || $item_type == 'all' ) $network_updates = 1;


                // var_dump($values[1]);

		//$rel = new UserActivity( $wgUser->getName(), ( ( $rel_type == 1 ) ? ' friends' : 'foes' ), 50 );
                $rel = new UserTimeline( $values[1], ( ( $rel_type == 1 ) ? ' friends' : 'foes' ), 10 );


                $rel->setActivityToggle( 'show_edits', $edits );
		$rel->setActivityToggle( 'show_votes', $votes );
		$rel->setActivityToggle( 'show_comments', $comments );
		$rel->setActivityToggle( 'show_gifts_rec', $gifts );
		$rel->setActivityToggle( 'show_relationships', $relationships );
		$rel->setActivityToggle( 'show_system_messages', $messages );
		$rel->setActivityToggle( 'show_system_gifts', $system_gifts );
		$rel->setActivityToggle( 'show_messages_sent', $messages_sent );


               

		

		/**
		 * Get all relationship activity
		 */
		//$activity = $rel->getActivityListGrouped();
                $activity = $rel->getActivityList();
                //$activity = $rel->simplifyPageActivity($type, $has_page);

                //var_dump($activity);

                //var_dump($rel);                                                                   // -------------------> getActivityList

		$border_fix = '';


               

		if ( $activity ) {
			$x = 1;

			foreach ( $activity as $item ) {

				if ( $x < 40 ) {

					if ( ( ( count( $activity ) > 40 ) && ( $x == 39 ) ) || ( ( count( $activity ) < 40 ) && ( $x == ( count( $activity ) - 1 ) ) ) ) {
						$border_fix = ' border-fix';
					}

					$out .= "<div class=\"user-home-activitss\">
						<img src=\"{$wgScriptPath}/extensions/SocialProfile/images/" . UserActivity::getTypeIcon( $item['type'] ) . "\" alt=\"\" border=\"0\" />
						{$item["data"]}
					</div>";
					$x++;
				}
			}
		}

		

    $out .= '</ul>';
    $out .= '</div>';
 


    $wgOut->switchBocataMode(true);
    $wgOut->setOrder(480);
    $wgOut->addHtml($out);
    $wgOut->resetOrder();
  }



}



 function ss_getActivityList() {
		if ( $this->show_edits ) $this->setEdits();
		if ( $this->show_votes ) $this->setVotes();
		if ( $this->show_comments ) $this->setComments();
		if ( $this->show_gifts_sent ) $this->setGiftsSent();
		if ( $this->show_gifts_rec ) $this->setGiftsRec();
		if ( $this->show_relationships ) $this->setRelationships();
		if ( $this->show_system_messages ) $this->getSystemMessages();
		if ( $this->show_system_gifts ) $this->getSystemGiftsRec();
		if ( $this->show_messages_sent ) $this->getMessagesSent();
		if ( $this->show_network_updates ) $this->getNetworkUpdates();

		if ( $this->items )
			usort( $this->items, array( 'UserActivity', 'sortItems' ) );
		return $this->items;
	}


